def prime(n):
    if n <= 1:
        return False
    for i in range(2, n):
        if n % i == 0:
            return False
    return True


nw = {'zero': '0',
      'one': '1',
      'two': '2',
      'three': '3',
      'four': '4',
      'five': '5',
      'six': '6',
      'seven': '7',
      'eight': '8',
      'nine': '9',
      'ten': '10'
      }

f = input().split()
if len(f) != 3:
    print('Wrong input')
elif f[0] not in nw:
    print('Wrong input')
elif f[1] not in nw:
    print('Wrong input')
elif f[2] not in nw:
    print('Wrong input')
elif f[0] == 'zero':
    print('Wrong input')

else:

    number = int(nw[f[0]] + nw[f[1]] + nw[f[2]])

    cp = number
    while not prime(cp):
        cp -= 1

    cp1 = number + 1
    while not prime(cp1):
        cp1 += 1

    if abs(number - cp) <= abs(number - cp1):
        closest_prime = cp
    else:
        closest_prime = cp1

    print(closest_prime)
